home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / pj64.arc / SMLTPLNT.C < prev    next >
Text File  |  1988-12-16  |  3KB  |  118 lines

  1. /* 
  2.   Initialization segment for the Windows small memory model template.
  3.   This code can be discarded after it is used.
  4.  */
  5.  
  6. #include <windows.h>
  7. #include "smltpl.h"
  8.  
  9. /* local function declarations */
  10. static BOOL NEAR RegisterWindowClass(HANDLE);
  11. static void NEAR GetPrevInstanceData(HANDLE);
  12. static BOOL NEAR MakeAndShowMainWnd(HANDLE, HANDLE, int);
  13.  
  14. /* This routine is FAR since it is called from another segment */
  15. BOOL FAR InitProgram(hInstance,hPrevInstance, lpszCmdLine, cmdShow)
  16. HANDLE hInstance, hPrevInstance;
  17. LPSTR lpszCmdLine;
  18. int cmdShow;
  19. {
  20.  
  21.   /* if this is the first instance of the program ... */
  22.     if (!hPrevInstance) {
  23.       /* register the window */
  24.     if (!RegisterWindowClass(hInstance))
  25.         return FALSE;
  26.     }
  27.   /* A previous instance already exists so get global data from there */
  28.     else
  29.     GetPrevInstanceData(hPrevInstance);
  30.  
  31.   /* Create and show the window */
  32.     if (!MakeAndShowMainWnd(hInstance,hPrevInstance, cmdShow))
  33.     return FALSE;
  34.  
  35.     return TRUE;
  36. }
  37.  
  38. /* Every window must belong to a class. We register ours here */
  39. static BOOL NEAR RegisterWindowClass(hInstance)
  40. HANDLE hInstance;
  41. {
  42.  
  43.     PWNDCLASS pWndClass;
  44.     HANDLE hTemp;
  45.  
  46.   /* Load the name string from resources */
  47.     LoadString(hInstance, IDS_APPNAME,(LPSTR)szAppName,sizeof(szAppName));
  48.  
  49.   /* allocate space for the WNDCLASS structure and lock it down */
  50.     hTemp = LocalAlloc(LPTR,sizeof(WNDCLASS));
  51.     pWndClass = (PWNDCLASS)LocalLock(hTemp);
  52.  
  53.   /* fill the structure */    
  54.     pWndClass->hCursor    = LoadCursor(NULL, IDC_ARROW);  /* standard cursor */
  55.     pWndClass->hIcon    = NULL;                /* no icon */
  56.     pWndClass->lpszMenuName = NULL;            /* no class menu */
  57.     pWndClass->lpszClassName = (LPSTR)szAppName;    /* our class name */
  58.     pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH); /*white background*/
  59.     pWndClass->hInstance = hInstance;        /* instance handle */
  60.     pWndClass->style = CS_VREDRAW | CS_HREDRAW; /* standard redraw values */
  61.     pWndClass->lpfnWndProc = MainWndProc;    /* pointer to our window proc */
  62.  
  63.   /* register the class.  if fail, abort */
  64.     if (!RegisterClass((LPWNDCLASS)pWndClass))
  65.     return FALSE;
  66.  
  67.   /* free the memory used */
  68.     LocalUnlock(hTemp);
  69.     LocalFree(hTemp);
  70.  
  71.   /* show success */
  72.     return TRUE;
  73. }
  74.  
  75. /*
  76.    If this not the first instance, we can retrieve static data from a
  77.    previous invocation of the program
  78. */
  79. static void NEAR GetPrevInstanceData(hInstance)
  80. HANDLE hInstance;
  81. {
  82.  
  83.     GetInstanceData(hInstance, (PSTR)szAppName, sizeof(szAppName));
  84.  
  85. }
  86.  
  87. /*
  88.  Create the window, making sure that its position and size are suitable
  89.  for the display.
  90. */
  91. static BOOL NEAR MakeAndShowMainWnd(hInstance, hPrevInstance, cmdShow)
  92. HANDLE hInstance;
  93. HANDLE hPrevInstance;
  94. int cmdShow;
  95. {
  96.  
  97.   /* create the window, letting it fall where Windows wants */
  98.     hWndMain = CreateWindow((LPSTR)szAppName,
  99.                  (LPSTR)szAppName,
  100.                  WS_OVERLAPPEDWINDOW,
  101.                  CW_USEDEFAULT,0,
  102.                  CW_USEDEFAULT,0,
  103.                  (HWND)NULL,
  104.                  (HMENU)NULL,
  105.                  (HANDLE)hInstance,
  106.                  (LPSTR)NULL);
  107.  
  108.   /* if we fail, give up */
  109.     if (hWndMain == NULL)
  110.     return FALSE;
  111.  
  112.   /* finally, display the window and show success */
  113.     ShowWindow(hWndMain, cmdShow);
  114.     UpdateWindow(hWndMain);
  115.  
  116.     return TRUE;
  117. }
  118.